#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 2e4+7;
const int INF = 0x7fffff;
int m, n;
int h[maxn], r[maxn];
int ans = INF;
void trace() {

}
// Current Layer, Current Surface, Current Volume (without bottom)
void dfs(int cl, int cs, int cv) {
  if(cs+r[1]*r[1]>=ans) return;
  if(cv>n) return;
  if(cv+r[cl-1]*r[cl-1]*h[cl-1]*(m+1-cl) < n) return;
  if(cs+r[1]*r[1]+2*(n-cv)/r[cl-1] > ans) return;
  if(cv == n && cl == m+1) {
    ans = min(ans, cs+r[1]*r[1]);
    trace();
    return;
  }
  if(cl>=m+1) return;
  for(int nr=m-cl+1; nr<r[cl-1]; ++nr) {
    for(int nh=m-cl+1; nh<h[cl-1]; ++nh) {
      h[cl] = nh, r[cl] = nr;
      dfs(cl+1, cs+2*nr*nh, cv+nr*nr*nh);
    }
  }
}

int main() {
  cin>>n>>m;
  r[0] = h[0] = sqrt(n);
  dfs(1, 0, 0);
  if(ans < INF) cout<<ans<<'\n';
  else cout<<"0\n";
}
